<template>
  <div class="container">
    <div style="margin-bottom: 10px;">我发布的岗位</div>
    <div v-for="item in mySubmitList" :key="item.id" class="cardContainer">
      <div style="color: #6a9af1;">
        {{item.companyName}} - {{item.post}} - {{item.workPlace}}
      </div>
      <div style="margin: 10px 0;">
        创建于 {{moment(item.createAt).format('YYYY-MM-DD')}}
      </div>
      <div @click="openDialog(item.id)" style="cursor: pointer;">
        查看投递
      </div>
    </div>
    <el-dialog
      title="投递的人"
      :visible.sync="visible"
      width="70%">
        <el-table :data="tableData">
          <el-table-column prop="name" label="姓名" width="150">
            <template slot-scope="scope">
              {{ scope.row.resumeInfo.basicInfo.name }}
            </template>
          </el-table-column>
          <el-table-column prop="sex" label="性别" width="150">
            <template slot-scope="scope">
              {{ scope.row.resumeInfo.basicInfo.sex ===1 ? '男' : '女'}}
            </template>
          </el-table-column>
          <el-table-column prop="phone" label="手机">
            <template slot-scope="scope">
              {{ scope.row.resumeInfo.basicInfo.phone}}
            </template>
          </el-table-column>
          <el-table-column prop="age" label="年龄">
            <template slot-scope="scope">
              {{ birthday(scope.row.resumeInfo.basicInfo.date)}}
            </template>
          </el-table-column>
          <el-table-column prop="operate" label="操作" width="150">
            <template slot-scope="scope">
              <el-button type="primary" @click="createPdf(scope.row.resumeInfo.basicInfo.name, scope.row.resumeInfo.basicInfo.userId)">查看简历</el-button>
            </template>
          </el-table-column>
        </el-table>
    </el-dialog>
  </div>
</template>

<script>
import moment from 'moment'
export default {
  data () {
    return {
      visible: false,
      mySubmitList: [],
      tableData: []
    }
  },
  methods: {
    birthday (timeData) {
      const newTime = (new Date()).getTime() / 1000
      const oldTime = (new Date(timeData)).getTime() / 1000
      return Math.floor((newTime - oldTime) / (60 * 60 * 24 * 365))
    },
    async createPdf (userName, userId) {
      this.$http({method: 'get', url: `/upload/createPdf/${userId}`, responseType: 'blob'}).then(res => {
        const data = res.data
        const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
        const link = document.createElement('a')
        link.style.display = 'none'
        link.href = url
        link.setAttribute('download', `${userName}的简历.pdf`)
        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link)
      })
    },
    async getMySubmitList () {
      const res = await this.$http.get('/job/mySubmit')
      this.mySubmitList = res.data
      console.log(this.mySubmitList, 'oooo')
    },
    async openDialog (jobId) {
      this.visible = true
      const res = await this.$http.get(`/resume/submitList/${jobId}`)
      this.tableData = res.data
    },
    moment
  },
  created () {
    this.getMySubmitList()
  }
}
</script>

<style lang="less" scoped>
.container {
  padding: 10px 150px;
  .cardContainer {
    padding: 10px;
    background-color: #fff;
    margin-bottom: 10px;
    border-radius: 10px;
  }
}

</style>
